
package tomkitty.turdlet;

import tomkitty.server.*;
import tomkitty.util.*;
import java.util.*;
import java.io.*;

public class StaticTurdlet extends TurdletBase implements HttpConstants {

	private String file = "index.html";

	public void setFile(String file) {
		this.file = file;
	}

	public StaticTurdlet(String file) {
		super();
		setFile(file);
	}

	public void doit() {

		String root = Main.getConfig().get("docroot");
		file = root + "/" + file;

		try {
			File f = new File(file);

			FileReader file_reader = new FileReader (file);
			BufferedReader buf_reader = new BufferedReader (file_reader);

			// Read each line of the file and look for the string of interest.
			do {
				String line = buf_reader.readLine();
				if (line == null) break;
				print(line);
			} while (true);
			buf_reader.close ();
		} catch (FileNotFoundException e1) {
			getHandler().NotFoundError(in, out, request);
		} catch (Exception e2) {
			e2.printStackTrace();
			getHandler().ServerError(in, out, request);
		}

	}

}

